package com.shop2cn.iapi.member.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.MemberPointsDto;
import com.shop2cn.iapi.member.parameter.MemberPointsListBean;
import com.shop2cn.iapi.member.service.MemberPointsListCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*会员积分列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MemberPointsList{
	private static MemberPointsListBean memberpointslistBean;
	private static MemberPointsListCall memberpointslistCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("会员积分列表");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		memberpointslistBean=new MemberPointsListBean();
		memberpointslistCall=new MemberPointsListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(memberpointslistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MemberPointsList_001() {
		Logger.start(true,"会员积分列表成功-送积分");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			Integer points=10;
			GodMemberService.sendPoints(memid, shopid, points);
			
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("200", memberpointslistCall.getString("code"), "验证code");
			//验证记录 送积分
			List<MemberPointsDto> results = memberpointslistCall.getMemberPointsListResp().getResults();
			Logger.verifyEquals(1, results.size(), "验证条数");
			Logger.verifyEquals(200000, results.get(0).getBizType(),"验证getBizType");
			Logger.verifyEquals(points, results.get(0).getChangePoints(),"验证points");
			Logger.verifyEquals(memid, results.get(0).getMemberId(),"验证memid");
			Logger.verifyEquals("主账号", results.get(0).getOperator(),"验证getOperator");
			Logger.verifyEquals(null, results.get(0).getOrderAmt(),"验证getOrderAmt");
			Logger.verifyEquals(null, results.get(0).getOrderId(),"验证getOrderId");
			Logger.verifyEquals("atuoTest", results.get(0).getRemark(),"验证getRemark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_002() {
		Logger.start(true,"不输入userid失败");
		try {
			memberpointslistBean.setShopId(shopid);
//			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("400", memberpointslistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_003() {
		Logger.start(true,"不输入shopid失败");
		try {
//			memberpointslistBean.setShopId(1);
			memberpointslistBean.setUserId(1);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("400", memberpointslistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_004() {
		Logger.start(true,"输入shopid和userid不匹配失败");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			memberpointslistBean.setShopId(shopid-1);
			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("300", memberpointslistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_005() {
		Logger.start(true,"不输入pageindex失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(userId);
//			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("400", memberpointslistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_006() {
		Logger.start(true,"不输入pagesize失败");
		try {
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(1);
			memberpointslistBean.setPageIndex(1);
//			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("400", memberpointslistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_007() {
		Logger.start(true,"会员积分列表成功-支付");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			//订单的points是算出来的 提前算好100=5
			Integer points=5;
//			GodMemberService.sendPoints(memid, shopid, points);
			Long orderid=Long.valueOf(TestDataManager.getRandomNum(10));
			String sqOrderRmbAmount="101";
			GodMemberService.processOrderPay(userId, shopid, orderid, sqOrderRmbAmount);
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("200", memberpointslistCall.getString("code"), "验证code");
			//验证记录 送积分
			List<MemberPointsDto> results = memberpointslistCall.getMemberPointsListResp().getResults();
			Logger.verifyEquals(1, results.size(), "验证条数");
			Logger.verifyEquals(100000, results.get(0).getBizType(),"验证getBizType");
			Logger.verifyEquals(points, results.get(0).getChangePoints(),"验证points");
			Logger.verifyEquals(memid, results.get(0).getMemberId(),"验证memid");
			Logger.verifyEquals("系统", results.get(0).getOperator(),"验证getOperator");
			Logger.verifyEquals(new BigDecimal(sqOrderRmbAmount).setScale(2),new BigDecimal( results.get(0).getOrderAmt()).setScale(2),"验证getOrderAmt");
			Logger.verifyEquals(orderid, results.get(0).getOrderId(),"验证getOrderId");
			Logger.verifyEquals("下单送积分", results.get(0).getRemark(),"验证getRemark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MemberPointsList_008() {
		Logger.start(true,"会员积分列表成功-扣积分");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			Integer points=10;
			Integer dpoints=-6;
			GodMemberService.sendPoints(memid, shopid, points);
			GodMemberService.sendPoints(memid, shopid, dpoints);
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("200", memberpointslistCall.getString("code"), "验证code");
			//验证记录 送积分
			List<MemberPointsDto> results = memberpointslistCall.getMemberPointsListResp().getResults();
			Logger.verifyEquals(2, results.size(), "验证条数");
			MemberPointsDto result = results.stream().filter(x->{return x.getBizType().equals(210000);}).findFirst().get();
			Logger.verifyEquals(210000, result.getBizType(),"验证getBizType");
			Logger.verifyEquals(dpoints, result.getChangePoints(),"验证points");
			Logger.verifyEquals(memid, result.getMemberId(),"验证memid");
			Logger.verifyEquals("主账号",result.getOperator(),"验证getOperator");
			Logger.verifyEquals(null, result.getOrderAmt(),"验证getOrderAmt");
			Logger.verifyEquals(null, result.getOrderId(),"验证getOrderId");
			Logger.verifyEquals("atuoTest", result.getRemark(),"验证getRemark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MemberPointsList_009() {
		Logger.start(true,"会员积分列表成功-取消支付");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			//订单的points是算出来的 提前算好100=5
			Integer points=5;
//			GodMemberService.sendPoints(memid, shopid, points);
			Long orderid=Long.valueOf(TestDataManager.getRandomNum(10));
			String sqOrderRmbAmount="101";
			GodMemberService.processOrderPay(userId, shopid, orderid, sqOrderRmbAmount);
			GodMemberService.processOrderCancelPay(userId, shopid, orderid,101);
			memberpointslistBean.setShopId(shopid);
			memberpointslistBean.setUserId(userId);
			memberpointslistBean.setPageIndex(1);
			memberpointslistBean.setPageSize(10);
			memberpointslistCall.setData(memberpointslistBean);
			memberpointslistCall.callService();			
			Logger.verifyEquals("200", memberpointslistCall.getString("code"), "验证code");
			//验证记录 送积分
			List<MemberPointsDto> results = memberpointslistCall.getMemberPointsListResp().getResults();
			Logger.verifyEquals(2, results.size(), "验证条数");
			MemberPointsDto result = results.stream().filter(x->{return x.getBizType().equals(110000);}).findFirst().get();
			Logger.verifyEquals(110000, result.getBizType(),"验证getBizType");
			Logger.verifyEquals(-points, result.getChangePoints(),"验证points");
			Logger.verifyEquals(memid, result.getMemberId(),"验证memid");
			Logger.verifyEquals("系统", result.getOperator(),"验证getOperator");
			Logger.verifyEquals(new BigDecimal(sqOrderRmbAmount).setScale(2),new BigDecimal( result.getOrderAmt()).setScale(2),"验证getOrderAmt");
			Logger.verifyEquals(orderid,result.getOrderId(),"验证getOrderId");
			Logger.verifyEquals("退款扣积分", result.getRemark(),"验证getRemark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}